home *** CD-ROM | disk | FTP | other *** search
- Path: oxy.rust.net!usenet
- From: ebennett@rust.net
- Newsgroups: comp.lang.c++
- Subject: Re: Question: references to variables within classes
- Date: Thu, 11 Jan 1996 05:15:44 GMT
- Organization: Rust Net - High Speed Internet in Detroit 810-642-2276
- Message-ID: <4d1rq9$sla@oxy.rust.net>
- References: <DKy0MC.3nA@watserv3.uwaterloo.ca>
- NNTP-Posting-Host: liv-16.rust.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- sdbay@watnow.uwaterloo.ca (Stephen Bay) wrote:
-
- >Hi,
-
- >Is it possible in C++ to use variables within a class as parameters for a
- >constructor of an object contained within that class? I've tried compiling the
- >following code and my compiler chokes on the list iter declaration within the
- >class dodo - it doesn't recognize CityList and gives a syntax error. All the
- >other statements compile fine though.
-
- >-stephen
-
-
- >#include "slist.hpp"
-
- >NISList<int *> CityList;
- >NISListIter<int *> CityListIter(CityList);
-
- >struct bird
- >{
- > NISList<int *> CityList;
- > NISListIter<int *> CityListIter();
- >};
-
- >class dodo
- >{
- > public:
- > NISList<int *> CityList;
- >chokes here-> NISListIter<int *> CityListIter(CityList);
- >};
-
- >main()
- >{
- > NISList<int *> CityList;
- > NISListIter<int *> CityListIter(CityList);
- >};
-
- You are trying to call the constructor for CityListIter within the
- class definition. This is illegal. You should be able to change this
- as follows:
-
- class dodo
- {
- public:
- NISLit<int *> CityList;
- NISListIter<int *> CityListIter;
-
- dodo() : CityListIter(CityList) {};
- };
-
- Since templates are involved, and I am not up to speed on templates, I
- am not 100% sure this will work this way, but it is what I would try
- first.
-
- Earl Bennett
-
-
-
-